#include "StdAfx.h"
#include "FileSendHandle.h"
#include "IOCPAsynServerSocket.h"

CFileSendHandle::CFileSendHandle(void)
{
}

CFileSendHandle::~CFileSendHandle(void)
{
	m_hIfstream.close();
}

void CFileSendHandle::HandleSend(CIOCPAsynServerSocket* _pServerSocket)
{
	++m_nCount;
	if (m_nCurrentPostion >= m_nFileSize)
	{

		//_pServerSocket->ResetSendHandle(this);
		//delete this;
		//return;
	}

	int nBuffLen = 4 + 4 + m_nFileSize;
	
	char* buff = new char[nBuffLen];
	int nPackageLen = nBuffLen - 4;
	int nPackageType = 1111;
	memcpy(buff,&nPackageLen,4);
	memcpy(buff + 4,&nPackageType,4);
	printf("packageType: %d, count %d\n",nPackageType,m_nCount);
	m_hIfstream.seekg(0,std::ios::beg);
	m_hIfstream.read(buff + 8, m_nFileSize);

	m_nCurrentPostion += m_nFileSize;

	_pServerSocket->PostSend(buff,nBuffLen,this);

}

void CFileSendHandle::HandleConnectionRemove(CIOCPAsynServerSocket* _pServerSocket){
	printf("handle remove\n");
}